import CoworkList from './leftList/';
import CoworkContent from './content/';
import CoworkRelateMeList from './CoworkRelateMeList.js';
import { inject, observer } from 'mobx-react';


@inject('coworkMainStore')
@observer
class CoworkField extends React.Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    const { coworkMainStore } = this.props;
    let { params } = this.props;
    let { coworkId, floorNum } = params;
    coworkMainStore.chooseCowork(coworkId, floorNum);
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.params.coworkId != this.props.params.coworkId ||
      nextProps.params.floorNum != this.props.params.floorNum) {
      const { coworkMainStore } = nextProps;
      coworkMainStore.chooseCowork(nextProps.params.coworkId, nextProps.params.floorNum);
    }
  }

  render() {
    let { params } = this.props;
    let { coworkId } = params;
    return (
      <div className="h100">
        <CoworkList ecId={`${this && this.props && this.props.ecId || ''}_CoworkList@559o11`} />
        {coworkId ? <CoworkContent ecId={`${this && this.props && this.props.ecId || ''}_CoworkContent@95kyz4`} coworkId={coworkId} /> : <CoworkRelateMeList ecId={`${this && this.props && this.props.ecId || ''}_CoworkRelateMeList@sk776o`} />}
      </div>
    );
  }
}

export default CoworkField;
